import xyz.migle.base.task.SQLTask



//@file:JvmName("Test")

fun hivesql(user:String,f: SQLTask.() -> Unit): SQLTask{
    //使用操作系统验证的kerberos用户执行sql语句
//    val keytabfile = "conf/user.keytab";
//    val krb5file = "conf/krb5.conf"
//    val jaasfile ="conf/jaas.conf"
//      需要在命令行中以-Dxxxx=xx 方式传入
//    System.setProperty("java.security.krb5.conf", krb5file)
//    System.setProperty("java.security.auth.login.config", jaasfile)
//    System.setProperty("zookeeper.sasl.client","false");
    val task = SQLTask()
    task.type = "hive"
    task.driverClassName="org.apache.hive.jdbc.HiveDriver"
    task.url = "jdbc:hive2://10.113.246.10:24002,10.113.246.9:24002,10.113.246.8:24002/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;sasl.qop=auth-conf;auth=KERBEROS;principal=hive/hadoop.fi1.com@FI1.COM"
    task.user =""
    task.pwd = ""
    task.f()
    return task
}
var j002 = job {
    author = "migle"
    jobId = "getJ001"
    jobName = "j001_name"
    jobDescribe = "job describe"
    period = "day"
    batch = "20180901"
    //NOTE:sql语句不能以分号”;"结尾
    task {
        hivesql("yx_qcd") {
            taskName = "create table test1"
            sql = "create table test_sqldsl(id int,name varchar(50))"
        }
    }
    task {
        hivesql("yx_qcd") {
            taskName = "create table test1"
            sql = "select coun(*) from test_sqldsl"
        }
    }

    onSuccess {
        print("is ok!")
    }
    onFail {
        //我定义通知
        print("is sorrowful!")
    }
}